import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/test'
    
  },


  {
    path: '/test',
    component: Layout,
    redirect: '/test/table',
    name: 'Test',
    meta: { title: '测试-数据管理模块', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'table', //创建一个test下的子路由，访问路径为 /test/table
        name: 'TestTable', //路由名称 一般使用完整路径拼接
        component: () => import('@/views/test/list'),
        meta: { title: '测试-数据列表管理', icon: 'table' }
      },
      {
        path: 'save',
        name: 'TestSave',
        component: () => import('@/views/test/form'),
        meta: { title: '测试-数据新增管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/integral-grade',
    component: Layout,
    redirect: '/integral-grade/list',
    name: 'Integral-grade',
    meta: { title: '积分等级管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'list', //创建一个test下的子路由，访问路径为 /integral-grade/list
        name: 'Integral-gradeList', //路由名称 一般使用完整路径拼接
        component: () => import('@/views/integralGrade/list'),
        meta: { title: '积分等级列表', icon: 'table' }
      },
      {
        path: 'save',
        name: 'Integral-gradeSave',
        component: () => import('@/views/integralGrade/form'),
        meta: { title: '新增积分等级', icon: 'form' }
      },
      {
        path: 'edit/:id', //vue可以通过:变量名  定义路径参数  变量名用来接收一级路径的值
        name: 'Integral-gradeSave',
        component: () => import('@/views/integralGrade/form'),
        meta: { title: '更新积分等级', icon: 'form' },
        hidden:true
      }
    ]
  },
  {
    path: '/dict',
    component: Layout,
    // redirect: '/dict/import',
    name: 'Dict',
    meta: { title: '数据字典管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'import', //创建一个test下的子路由，访问路径为 /integral-grade/list
        name: 'DictImport', //路由名称 一般使用完整路径拼接
        component: () => import('@/views/dict/import'),
        meta: { title: '数据字典管理', icon: 'table' }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/list',
    name: 'User',
    alwaysShow:true,
    meta: { title: '会员管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'list', //创建一个test下的子路由，访问路径为 /integral-grade/list
        name: 'UserList', //路由名称 一般使用完整路径拼接
        component: () => import('@/views/user/list'),
        meta: { title: '会员列表', icon: 'table' }
      }
    ]
  },
  {
    path: '/borrower',
    component: Layout,
    redirect: '/borrower/list',
    name: 'Borrower',
    meta: { title: '借款管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'list', //创建一个test下的子路由，访问路径为 /integral-grade/list
        name: 'BorrowerList', //路由名称 一般使用完整路径拼接
        component: () => import('@/views/borrower/list'),
        meta: { title: '借款人列表', icon: 'table' }
      },
      {
        path: 'edit/:id', //创建一个test下的子路由，访问路径为 /integral-grade/list
        name: 'BorrowerEdit', //路由名称 一般使用完整路径拼接
        component: () => import('@/views/borrower/form'),
        hidden:true,
        meta: { title: '借款人详情', icon: 'form' }
      },
      {
        path: 'borrower-info', //创建一个test下的子路由，访问路径为 /integral-grade/list
        name: 'BorrowerInfo', //路由名称 一般使用完整路径拼接
        component: () => import('@/views/borrower/borrowerInfo'),
        // hidden:true,
        meta: { title: '借款列表', icon: 'form' }
      },
      {
        path: 'detail/:id', //创建一个test下的子路由，访问路径为 /integral-grade/list
        name: 'BorrowerInfoDetail', //路由名称 一般使用完整路径拼接
        component: () => import('@/views/borrower/detail'),
        hidden:true,
        meta: { title: '借款详情', icon: 'table' }
      }
    ]
  },
  {
    path: '/lend',
    component: Layout,
    redirect: '/lend/list',
    name: 'Lend',
    alwaysShow:true,
    meta: { title: '标的管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'list', //创建一个test下的子路由，访问路径为 /integral-grade/list
        name: 'LendList', //路由名称 一般使用完整路径拼接
        component: () => import('@/views/lend/list'),
        meta: { title: '标的列表', icon: 'table' }
      },
      {
        path: 'detail/:id', //创建一个test下的子路由，访问路径为 /integral-grade/list
        name: 'LendDetail', //路由名称 一般使用完整路径拼接
        component: () => import('@/views/lend/form'),
        hidden:true,
        meta: { title: '标的详情', icon: 'form' }
      },
      {
        path: 'lend-return/:id', //创建一个test下的子路由，访问路径为 /integral-grade/list
        name: 'LendReturn', //路由名称 一般使用完整路径拼接
        component: () => import('@/views/lend/lend-return'),
        hidden:true,
        meta: { title: '还款计划', icon: 'form' }
      }
    ]
  }


]

export const asyncRoutes = [
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
